<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.Project"%>
<%@page import="db.ProjectDAO"%>
<%@page import="db.SubstoreDAO" %>
<%@ include file="/jsp/common/utility/volti.jsp" %>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	request.setCharacterEncoding("utf-8");
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ProjectDAO projectDAO = (ProjectDAO)ctx.getBean("ProjectDAO");
	SubstoreDAO substoreDAO = (SubstoreDAO)ctx.getBean("SubstoreDAO");
	List list = substoreDAO.findAll();
	request.setAttribute("substore",list);
	//System.out.println("==================>"+session.getAttribute("tid"));
	String name = request.getParameter("sname");
	String substoreid = request.getParameter("subselect");
	int subid = 0;
	if(substoreid==null || "".equals(substoreid)){
		subid = 0;
	}else{
		subid = Integer.parseInt(substoreid);
	}
	request.setAttribute("subid",subid);
	if(name==null ||"请输入项目名称关键字".equalsIgnoreCase(name) || name=="请输入项目名称关键字"){
		name = "";
	}
	String message = "";
	
	String pagenem = request.getParameter("pageNo");
	int pn=0;
	if(pagenem==null || "".equals(pagenem)){
		pn=0;
	}else{
		pn = Integer.parseInt(pagenem);
	}
	//每页多少条
	int pageSize = 10;
	
	int tid = (Integer)session.getAttribute("tid");
	Object[][] ob = new Object[][]{};
	List listob = new ArrayList();
	if(name!=null && subid!=0){
		listob.add(new Object[]{"like","name",name});
		listob.add(new Object[]{"like","code",name});
		ob = new Object[][]{new Object[]{"or","",listob},new Object[]{"eq","substoreId",subid},new Object[]{"eq","isDelete",0}};
	}else {
		listob.add(new Object[]{"like","name",name});
		listob.add(new Object[]{"like","code",name});
		ob = new Object[][]{new Object[]{"or","",listob},new Object[]{"eq","isDelete",0}};
	}
	
	Map map = projectDAO.getProject(pn,pageSize,new String[][]{new String[]{"desc","date"}},ob,
	new String[][]{new String[]{"","id"},new String[]{"","s.name"},new String[]{"","code"},new String[]{"","name"},new String[]{"","subCode"},new String[]{"","subName"},new String[]{"","manager"}},
	new String[]{"substore"}
	);
	//userDao.getMaterials(0, 0, new String[][]{new String[]{"desc","createDate"}}, new Object[][]{new Object[]{"eq","userId",userId},new Object[]{"eq","folderId",obj[0]},new Object[]{"eq","state","1"}}, new String[][]{new String[]{"","id"},new String[]{"","tag"},new String[]{"","MType"},new String[]{"","UType"},new String[]{"","t.createDate"},new String[]{"","path"}}, new String[]{"title","grope"});
	List li = (List) map.get("data");
	//System.out.println("========================>"+li.size());
	map.put("data",getListReMap(li));
	//System.out.println(map.get("recordSize")+"==========="+map.get("pageTotal")+"=============="+map.get("pageSize"));
	//-----------------------------------分页-------------------------------------
		//List allnews=webNodeService.getSimpleNodeListByPnid(2,newsNodeid,0,999,1,0,true);
		//int pageCount= map.get("recordSize")%pageSize==0 ? allnews.size()/pageSize:allnews.size()/pageSize+1;
		int pageTotal = (Integer)map.get("pageTotal");
		int pageNo = (Integer)map.get("pageNo");
		List pageList=getPage(pageTotal,pageNo);
	//----------------------------------request.setAttribute()---------------------
		
		request.setAttribute("map",map);
		request.setAttribute("pages",pageList);
		//下拉菜单选中项
		if(name=="" || "请输入项目名称关键字".equals(name) || "".equals(name) || "请输入项目名称关键字"==name){
			request.setAttribute("sname","请输入项目名称关键字");
		}else{
			request.setAttribute("sname",name);
		}
		
		
		
		
		pageContext.forward("/vm/prinfo/prinfo_list.vm");
%>
<%!
	public List getListReMap(List list){
		List listmap = new ArrayList();
		//System.out.println("===============>>>>>>>>");
		if(list != null && list.size()>0){
		
			for(int i=0;i<list.size();i++){
			
				Map map = new HashMap();
				Object[] aa= (Object[]) list.get(i);
				
				System.out.println("11111111=========>"+aa[0]+"====="+aa[1]+"===="+aa[2]+"===="+aa[3]+"===="+aa[4]+"======"+aa[5]+"===="+aa[6]);
				map.put("sid", aa[0]);
				map.put("sname", aa[1]);
				map.put("procode", aa[2]);
				map.put("proname", aa[3]);
				map.put("subcode", aa[4]);
				map.put("subname", aa[5]);
				map.put("company", aa[6]);
				listmap.add(map);
			}
		}
		return listmap;
	}
%>